home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
C
/
Comet2.1.3.cpt
/
Comet
/
tftp.h
< prev
next >
Wrap
Text File
|
1991-02-11
|
7KB
|
207 lines
/* Copyright 1984 by the Massachusetts Institute of Technology */
/*
Copyright Cornell University 1986. All rights are reserved.
As of 4/10/86:
This source file may have no changes from the M.I.T original
other than this notice; but it has been tested as part of
Cornell's Aztec-C port. See notice.h
*/
/* See permission and disclaimer notice in file "notice.h" */
#include <notice.h>
/* 10/1/84 - added definition of dos_eof as control Z since <stdio.h>
no longer defines it. <John Romkey>
11/29/84 - changed round-trip time initial estimate to 2.5 sec
to accomodate overloaded VAX unix systems.
<J. H. Saltzer>
2/28/87 kevin changed timeout times to reflect 60/ticks second on the Mac.
10/29/87 kevin made tfkill() a function
*/
#include <stdio.h>
#include <q.h>
#include <timer.h>
#include <MacTCPCommonTypes.h>
#include <UDPPB.h>
/* TFTP header file contains structures of TFTP packet headers and such. */
/* read or write request packet */
struct tfreq {
unsigned tf_op; /* would be 1 (read) or 2 (write) */
char tf_name[20];
};
/* data packet */
struct tfdata {
unsigned tf_op; /* would be 3 */
unsigned tf_block;
char tf_data[512];
};
/* structure of an ack packet */
struct tfack {
unsigned tf_op; /* would be 4 */
unsigned tf_block;
};
/* error packet */
#define TFERRLEN 80
struct tferr {
unsigned tf_op; /* would be 5 */
unsigned tf_code;
char tf_err[TFERRLEN];
};
/* TFTP opcodes */
#define RRQ 1 /* read request */
#define WRQ 2 /* write request */
#define DATA 3 /* data packet */
#define ACK 4 /* acknowledgement packet */
#define ERROR 5 /* error packet */
/* TFTP error codes */
#define ERRTXT 0 /* see the enclosed text */
#define FNOTFOUND 1 /* file not found */
#define ACCESS 2 /* access violation */
#define DISKFULL 3 /* don't even ask. */
#define ILLTFTP 4 /* illegal TFTP operation */
#define BADTID 5 /* unkown transfer ID */
#define FEXISTS 6 /* file already exists */
#define NOUSER 7 /* no such user */
/* TFTP states */
#define INIT 0
#define DATAWAIT 1
#define ACKWAIT 2
#define DEAD 3
#define TIMEOUT 4
#define RCVERR 5
#define RCVACK 6
#define RCVDATA 7
#define RCVLASTDATA 8
#define TERMINATED 9
#define TFTPSOCK 69 /* TFTP's well known port */
#define TFTPTRIES 20 /* # of retries on packet transmission */
#define REQTRIES 4 /* # of retries on initial request */
#define REQLEN 512 /* stupid, stupid... */
#define NORMLEN 512 /* normal length of received packet */
#define MACUDPLEN 2048 /* minimum UDP buffer for MacTCP */
#define tftp_data(p) ((struct tfdata *)((p)))->tf_data
/* The TFTP connection structure. Contains connection info, and data for
timeout calculations. */
struct tfconn {
UDPiopb *tf_udp; /* udp control block for this transfer */
FILE *tf_fd; /* file descriptor for xfer */
char * tf_outp; /* last sent packet */
unsigned tf_lastlen; /* length of last sent pkt */
unsigned tf_expected; /* most recently processed block */
ip_addr tf_host; /* host address */
unsigned short tf_port; /* host port # */
unsigned tf_haveport; /* we've got the foreign port */
timer *tf_tm; /* our timer */
unsigned tf_state; /* state of connection */
unsigned tf_tries; /* # of retries already done */
unsigned tf_mode; /* mode = IMAGE, [net]ASCII, ... */
unsigned tf_dir; /* direction of the transfer */
long tf_size; /* # of bytes transferred */
unsigned tf_rcv; /* # of packets received */
unsigned tf_snt; /* # of packets sent */
unsigned tf_ous; /* # of out of sequence packets */
unsigned tf_ntmo; /* # of timeouts */
unsigned tf_rsnd; /* # of resends */
long tf_trt; /* round trip time */
long tf_rt; /* current timeout */
int tf_NR; /* number rexmissions of this pkt */
int tf_NR_last; /* " " " of prev pkt */
int tf_K; /* tuning constant */
long tf_sent; /* time that pkt was sent */
StreamPtr stream; /* the MacTCP udp stream * */
};
/* Constants for round trip time estimation and retry timeout.
All calculation is done in clock ticks (at a rate of 18/second) but
only the initial estimate and the upper limit are specified in ticks;
the rest of the algorithm uses dimensionless multipliers. */
#define Kinit 3 /* Initial divisor for (1+1/K) estimate multiplier. */
#define Kinc 1 /* Reduce K by this if previous packet lost. */
#define T0 180 /* 2.5 secs Initial value for round trip time estimate. */
#define MAXTMO 720 /* 12 sec. upper limit on retry timeout timer, in ticks. */
#define TMMULT 3 /* multiplier to get retry timeout from round trip
estimate. */
/* TFTP randoms */
#define GET 10 /* GET file from other host to here */
#define PUT 11 /* PUT file on other host */
#define ASCII 1 /* transfer as netascii */
#define IMAGE 2 /* transfer as image */
#define TEST 3 /* test mode - diskless */
#define OCTET 4 /* octet mode - same as image */
int mtcp_tftprcv(); /* packet receive routine */
int mtcp_tftptmo(); /* timeout handler */
long mtcp_tfcleanup();
long tftpuse();
long atol();
pascal void udp_event();
extern char *tftplog;
extern unsigned long cticks;
extern int ntftps;
extern int tfsdata;
extern int tftpdata;
extern short ipp_refnum; /* from tcp.c */
extern int closeflag; /* from tcp.c */
extern UDPiopb tfspb;
extern UDPiopb tftppb;
extern int tfs_read_req;
extern int tfs_read_comp;
extern int tftp_read_req;
extern int tftp_read_comp;
void tfs_read_done();
void tftp_read_done();
extern struct tfconn tfsconn;
extern struct tfconn tftpconn;
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) > (y) ? (x) : (y))
/* the following are trace defines, mostly unused */
#define BUGHALT 1 /* BUGHALT on a gross applications level error
that is detected in the network code */
#define DUMP 2 /* Do a dump of all bad incoming packets */
#define INFOMSG 4 /* Print informational messages such as packet
received, etc. */
#define NETERR 8 /* Display net interface error messages */
#define PROTERR 16 /* Display protocol level error messages */
#define TRACE 32 /* Trace packet through protocol layers */
#define NETRACE 32 /* Trace packet in link level net layer */
#define INTRACE 32 /* Trace packet in internet layer */
#define TCTRACE 32 /* Transmission control (UDP, TCP) trace */
#define APTRACE 128 /* Trace packet through application */
#define TMO 64 /* Print message on timeout */
#define ROUTE 128 /* turn on routing tracing */
#define TCPTRACE 256
#define OFF 0
#define ON 1